package cn.chint.util;

import org.apache.log4j.Logger;

public class PushMsg {

	public static  Logger log = Logger.getLogger(PushMsg.class);
	
	/***审核通过通知***/
	public static String  push_msg(String openid,String first_value,String keyword1_value,String keyword2_value,String remark_value,String redic_url)  {
		try{
			log.info("模板消息推送TEST");

			String appid="wx487b598049f3a162"   ;
			String secret = "7afd7b083512837aad16295d2de49b22";
			/**获取TOKEN信息*/
			String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;
			log.info("token请求地址: "+ url);
			String res_json = HTTPClientUtils.getRequest(url);
			log.info("返回token信息: "+ res_json);

			com.alibaba.fastjson.JSONObject o = com.alibaba.fastjson.JSONObject.parseObject(res_json);
			String token = o.getString("access_token");
			//o3PxO0aGXf8hOmYoE39MJTqWzAOk


			com.alibaba.fastjson.JSONObject  jsonObject  = new com.alibaba.fastjson.JSONObject ();
			jsonObject.put("touser", openid);
			jsonObject.put("template_id", "Qsue3wzV8AcnAFaTYiEHzDdrziHPK_uJpnBNi9LezmY");
			if(redic_url !=null){
				jsonObject.put("url", redic_url);
			}

			com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
			com.alibaba.fastjson.JSONObject first = new com.alibaba.fastjson.JSONObject();
			first.put("value", first_value);
			first.put("color", "#173177");

			com.alibaba.fastjson.JSONObject keyword1 = new com.alibaba.fastjson.JSONObject();
			keyword1.put("value", keyword1_value);
			keyword1.put("color", "#173177");

			com.alibaba.fastjson.JSONObject keyword2 = new com.alibaba.fastjson.JSONObject();
			keyword2.put("value", keyword2_value);
			keyword2.put("color", "#173177");

			com.alibaba.fastjson.JSONObject remark = new com.alibaba.fastjson.JSONObject();
			remark.put("value", remark_value);
			remark.put("color", "#173177");

			data.put("first",first);
			data.put("keyword1",keyword1);
			data.put("keyword2",keyword2);
			data.put("remark",remark);

			jsonObject.put("data", data);

			String post_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token ;
			String res_info =  HTTPClientUtils.postRequest(post_url, jsonObject.toJSONString());
			log.info(res_info);

			return res_info;
		}catch (Throwable e) {
			e.printStackTrace();
			log.info("错误信息"+e.getMessage());
			return null;
		}
	}

	/***服务提交通知***/
	public static String  submit_push_msg(String openid,String first_value,String keyword1_value,String keyword2_value,String keyword3_value,String keyword4_value,String redic_url)  {
		try{
			String appid="wx487b598049f3a162"   ;
			String secret = "7afd7b083512837aad16295d2de49b22";
			/**获取TOKEN信息*/
			String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;
			log.info("token请求地址: "+ url);
			String res_json = HTTPClientUtils.getRequest(url);
			log.info("返回token信息: "+ res_json);

			com.alibaba.fastjson.JSONObject o = com.alibaba.fastjson.JSONObject.parseObject(res_json);
			String token = o.getString("access_token");
			//o3PxO0aGXf8hOmYoE39MJTqWzAOk


			com.alibaba.fastjson.JSONObject  jsonObject  = new com.alibaba.fastjson.JSONObject ();
			jsonObject.put("touser", openid);
			jsonObject.put("template_id", "_OCFcDvzd-XkfdvtbzhYb9FPqTtjQtCsVDhUCGp56tU");
			if(redic_url !=null){
				jsonObject.put("url", redic_url);
			}

			com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
			com.alibaba.fastjson.JSONObject first = new com.alibaba.fastjson.JSONObject();
			first.put("value", first_value);
			first.put("color", "#173177");

			com.alibaba.fastjson.JSONObject keyword1 = new com.alibaba.fastjson.JSONObject();
			keyword1.put("value", keyword1_value);
			keyword1.put("color", "#173177");

			com.alibaba.fastjson.JSONObject keyword2 = new com.alibaba.fastjson.JSONObject();
			keyword2.put("value", keyword2_value);
			keyword2.put("color", "#173177");

			com.alibaba.fastjson.JSONObject keyword3 = new com.alibaba.fastjson.JSONObject();
			keyword3.put("value", keyword3_value);
			keyword3.put("color", "#173177");
			
			com.alibaba.fastjson.JSONObject keyword4 = new com.alibaba.fastjson.JSONObject();
			keyword4.put("value", keyword4_value);
			keyword4.put("color", "#173177");

			data.put("first",first);
			data.put("keyword1",keyword1);
			data.put("keyword2",keyword2);
			data.put("keyword3",keyword3);
			data.put("keyword4",keyword4);

			jsonObject.put("data", data);

			String post_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token ;
			String res_info =  HTTPClientUtils.postRequest(post_url, jsonObject.toJSONString());
			log.info(res_info);

			return res_info;
		}catch (Throwable e) {
			e.printStackTrace();
			log.info("错误信息"+e.getMessage());
			return null;
		}
	}
	
	/***审核结果通知***/
	public static String  push_msg_result(String openid,String first_value,String keyword1_value,String keyword2_value,String remark_value,String redic_url)  {
		try{
			String appid="wx487b598049f3a162"   ;
			String secret = "7afd7b083512837aad16295d2de49b22";
			/**获取TOKEN信息*/
			String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;
			log.info("token请求地址: "+ url);
			String res_json = HTTPClientUtils.getRequest(url);
			log.info("返回token信息: "+ res_json);

			com.alibaba.fastjson.JSONObject o = com.alibaba.fastjson.JSONObject.parseObject(res_json);
			String token = o.getString("access_token");
			//o3PxO0aGXf8hOmYoE39MJTqWzAOk


			com.alibaba.fastjson.JSONObject  jsonObject  = new com.alibaba.fastjson.JSONObject ();
			jsonObject.put("touser", openid);
			jsonObject.put("template_id", "bDIZIPsFpjA5ZBNe5jbFX9bHx8z6YZEcVrrN5WjOjQg");
			if(redic_url !=null){
				jsonObject.put("url", redic_url);
			}

			com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
			com.alibaba.fastjson.JSONObject first = new com.alibaba.fastjson.JSONObject();
			first.put("value", first_value);
			first.put("color", "#173177");

			com.alibaba.fastjson.JSONObject keyword1 = new com.alibaba.fastjson.JSONObject();
			keyword1.put("value", keyword1_value);
			keyword1.put("color", "#173177");

			com.alibaba.fastjson.JSONObject keyword2 = new com.alibaba.fastjson.JSONObject();
			keyword2.put("value", keyword2_value);
			keyword2.put("color", "#173177");

			com.alibaba.fastjson.JSONObject remark = new com.alibaba.fastjson.JSONObject();
			remark.put("value", remark_value);
			remark.put("color", "#173177");
	

			data.put("first",first);
			data.put("keyword1",keyword1);
			data.put("keyword2",keyword2);
			data.put("remark",remark);

			jsonObject.put("data", data);

			String post_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token ;
			String res_info =  HTTPClientUtils.postRequest(post_url, jsonObject.toJSONString());
			log.info(res_info);

			return res_info;
		}catch (Throwable e) {
			e.printStackTrace();
			log.info("错误信息"+e.getMessage());
			return null;
		}
	}
	
}
